// const  BASEURL  =  'https://www.360haoming.com/api/'; //测试	
// const  BASEURL  =  'https://javatest.heiwangke.net/calculate-api/'; //线上
const  BASEURL  =  'https://calculate.weitukongjian.com/calculate-api/'; //正式线上
 
const request = (config) => {
	let header = {
		"Content-Type": config.contentType || "application/json;charset=utf-8",
	}
	return new Promise((resove, reject) => {
		uni.request({
			url: BASEURL + config.url,
			data: config.data || '',
			header: {
				'Authorization': 'Bearer ' +  uni.getStorageSync('token'),
			},
			method: config.method,
			dataType: "json",
			success: (res) => {
				const { data } = res
				const { code, result } = data
				switch(code){
					case 200:
					resove(res.data)
					break
					case 401:
					uni.reLaunch({
						url:'/pages/index/login'
					})
					break
					default:
					resove(res.data)
					uni.showToast({
						title: data.msg,
						duration:3000,
						mask:false,
						icon:"none"
					})
				}
			},
			fail: (error) => {
				
				uni.showToast({
					title:"请求错误",
					duration:1500,
					mask:false,
					icon:"none"
				});
				reject(error)
			},
			complete: () => {
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			}
		})
	})
}
export default request